using HQLAddin.Highlighting;
using HQLAddin.Tests.SnapshotUtils;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Moq;
using NUnit.Framework;
using SharpTestsEx;

namespace HQLAddin.Tests.Highlighting
{
	public class IsInQueryTagExtensionTests
	{
		[Test]
		public void WhenCurrentLineIsInsideQueryTagsThenIsInQueryTagsReturnsTrue()
		{
			var lines = new[]
			            	{
								"<query name=\"Foo\">",
								"from Foo",
								"</query>"
			            	};
			var span = SnapshotUtil.CreateSnapshot(lines).CreateSpanFromLineNumber(1);
			span.IsInQueryTag().Should().Be.True();
		}

		[Test]
		public void WhenCurrentLineIsNotInsideQueryTagsThenIsInQueryTagsReturnsFalse()
		{
			var lines = new[]
			            	{
								"<property name=\"Foo\"/>",
								"<property name=\"Bar\"/>",
								"<property name=\"Baz\"/>",
			            	};
			var span = SnapshotUtil.CreateSnapshot(lines).CreateSpanFromLineNumber(1);
			span.IsInQueryTag().Should().Be.False();
		}

		[Test]
		public void WhenCurrentLineIsDownToACloseQueryTagThenIsInQueryTagsReturnsFalse()
		{
			var lines = new[]
			            	{
								"<query name=\"Foo\">",
								"from Foo",
								"</query>",
								"<class>",
								"<property name=\"Foo\"/>",
								"<property name=\"Bar\"/>",
								"<property name=\"Baz\"/>",
			            	};
			var span = SnapshotUtil.CreateSnapshot(lines).CreateSpanFromLineNumber(5);
			span.IsInQueryTag().Should().Be.False();
		}

		[Test]
		public void WhenCurrentLineIsInsideCommentsThenIsInQueryTagsReturnsFalse()
		{
			var lines = new[]
			            	{
								"<!--",
								"<query name=\"Foo\">",
								"from Foo",
								"</query>"
			            	};
			var span = SnapshotUtil.CreateSnapshot(lines).CreateSpanFromLineNumber(2);
			span.IsInQueryTag().Should().Be.False();
		}

		[Test]
		public void WhenCurrentLineIsDownToCommentsThenIsInQueryTagsReturnsTrue()
		{
			var lines = new[]
			            	{
								"<!-- aaa -->",
								"<query name=\"Foo\">",
								"from Foo",
								"</query>"
			            	};
			var span = SnapshotUtil.CreateSnapshot(lines).CreateSpanFromLineNumber(2);
			span.IsInQueryTag().Should().Be.True();
		}
	}
}